package com.lion.queue.runner;
/**
 * 队列元素
 * @author liyongyao
 *
 * @param <T>
 */
public class QueueItem<T> implements Comparable<QueueItem<T>> {
	private int priority;
	private T entity;

	/**
	 * 数字越大，优先级越高
	 */
	@Override
	public int compareTo(QueueItem<T> o) {
		return this.priority < o.priority ? 1 : this.priority > o.priority ? -1
				: 0;
	}

	@Override
	@SuppressWarnings("unchecked")
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		QueueItem<T> obj = null;
		if (o instanceof QueueItem) {
			obj = (QueueItem<T>) o;
			if (obj.getEntity() == null) {
				return false;
			} else {
				return obj.getEntity().equals(this.getEntity());
			}
		}
		return super.equals(o);
	}

	public T getEntity() {
		return entity;
	}

	public void setEntity(T entity) {
		this.entity = entity;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

}
